﻿using System;

using CallNumberSystem;

using GeuSoftWareBLL;

namespace LengthAiCalculate
{
    public class SysInit
    {
        public static string DbConn = Properties.Settings.Default.DbConn;

        public static string SbDbConn = Properties.Settings.Default.SbDbConn;

        public static string DecryptDbConn()
        {
            try
            {
                return DPAPI.Decrypt(Properties.Settings.Default.DbConn, "GeuSoftWare.com", out _);
            }
            catch
            {
                return null;
            }
        }

        public static string DecryptSbDbConn()
        {
            try
            {
                return DPAPI.Decrypt(Properties.Settings.Default.SbDbConn, "GeuSoftWare.com", out _);
            }
            catch
            {
                return null;
            }
        }

        public static string GetDispatchTemplateID(int hour, int classTypeID)
        {
            if (classTypeID == 1)
            {
                if (hour > 12 && hour <= 19)
                {
                    hour = 20;
                }
                else if (hour >= 8 && hour <= 12)
                {
                    hour = 7;
                }
            }
            else
            {
                if (hour >= 0 && hour < 8)
                {
                    hour = 8;
                }
                else if (hour >= 20 && hour <= 23)
                {
                    hour = 19;
                }
            }
            int nHour = hour + 1;
            if (nHour >= 24)
            {
                nHour = 0;
            }
            return hour.ToString("00") + ":00-" + nHour.ToString("00") + ":00";
        }

        public static int SocketPort { set; get; } = 20480;

        public static SocketServerHelper SocketServer;

        /// <summary>
        /// 补料通知次数
        /// </summary>
        public static int NoteNum { set; get; } = 1;

        public static string GetVersion()
        {
            Version version = System.Reflection.Assembly.GetExecutingAssembly().GetName().Version;
            string v1 = "1.0.0";
            if (version != null)
            {
                v1 = version.ToString();
            }
#if DEBUG
            return "软件版本:Debug";
#else

            try
            {
                return "当前软件版本:v" + System.Deployment.Application.ApplicationDeployment.CurrentDeployment.CurrentVersion.ToString() + "(ClickOnce)";
            }
            catch
            {
                try
                {
                    Version v = System.Reflection.Assembly.GetExecutingAssembly().GetName().Version;
                    if (v != null)
                    {
                        return v.ToString() + "(local)";
                    }
                    else
                    {
                        return "当前软件版本:未知版本";
                    }
                }
                catch
                {
                    return "当前软件版本:未知版本";
                }
            }
#endif
        }

        /// <summary>
        /// 获取中和管理系统数据库地址
        /// </summary>
        /// <returns> </returns>
        public static string GetSBServer()
        {
#if DEBUG

            //return @"[SQJX-S1\MSSQLSERVER2008].SB_Manage.dbo.";

            return @"[SQJX-S1\MSSQLSERVER2008].SB_Manage.dbo.";
#else

            return @"[SQJX-S1\MSSQLSERVER2008].SB_Manage.dbo.";
#endif
        }
    }
}